package com.anket.address.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.anket.address.dao.AddressDao;
import com.anket.city.model.City;
import com.anket.country.model.Country;
import com.anket.district.model.District;
import com.hibernate.util.HibernateUtil;

public class AddressDaoImpl implements AddressDao{


	public List<Country> getAllCountries() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Query q=session.createQuery("from Country");
		return q.list();
	}


	public List<City> getAllCities(Integer countryId) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Query q=session.createQuery("from City where COUNTRY_ID=:id");
		q.setString("id", countryId.toString());
		return q.list();
	}


	public List<District> getAllDistricts(Integer cityId) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Query q=session.createQuery("from District where CITY_ID=:id");
		q.setString("id", cityId.toString());
		return q.list();
	}

}
